package ai.people.netmon.msgsearch.mapstruct;

import ai.people.netmon.framework.domain.searchmsg.bean.InfoData;
import ai.people.netmon.framework.domain.searchmsg.request.DataQuery;
import ai.people.netmon.framework.domain.searchmsg.request.MessageRequest;
import ai.people.netmon.msgsearch.domain.response.InfoDataResult;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.stereotype.Repository;

@Repository
@Mapper(componentModel = "spring")
public interface InfoDataConverter {
    //InfoDataConverter INSTANCE = Mappers.getMapper(InfoDataConverter.class);

    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "content", target = "content"),
            @Mapping(target = "pubtime", expression = "java(ai.people.netmon.utils.StringUtils.formatDate(\"yyyy-MM-dd HH:mm:ss\", infoData.getDate()))"),
            @Mapping(target = "ps", expression = "java(ai.people.netmon.utils.StringUtils.formatShortTimestamp(\"yyyy-MM-dd HH:mm:ss\", infoData.getTs()))"),
            @Mapping(source = "user_id", target = "author.id"),
            @Mapping(source = "user_name", target = "author.name"),
            @Mapping(source = "group_id", target = "group.id"),
            @Mapping(source = "site_name", target = "sitename"),
            @Mapping(source = "domain", target = "domain"),
            @Mapping(source = "group_name", target = "group.name")
    })
    InfoDataResult toInfoDataResult(InfoData infoData);



    @Mappings({
            @Mapping(source = "searchKeywords", target = "q"),
            @Mapping(source = "source", target = "source"),
            @Mapping(source = "startDate", target = "ps"),
            @Mapping(source = "endDate", target = "pe"),
            @Mapping(source = "fields", target = "fields"),
            @Mapping(source = "tags", target = "tags"),
            @Mapping(source = "sort", target = "sort"),
            @Mapping(source = "offset", target = "offset"),
            @Mapping(source = "limit", target = "limit"),
            @Mapping(source = "accountId", target = "author.id"),
            @Mapping(source = "accountName", target = "author.name"),
            @Mapping(source = "groupId", target = "group.id"),
            @Mapping(source = "groupName", target = "group.name")
    })
    DataQuery toInfoDataQuery(MessageRequest messageRequest);

}
